<template>
  <div>进度{{numText}}</div>
  <div>公钥{{address}}</div>
  <div>私钥{{privateKey}}</div>
  <el-button type="primary" @click="start()">开始</el-button>
</template>
<script setup>
import { ref, computed, onMounted } from "vue"
import {ethers} from "ethers";

onMounted(()=>{


})

const num = ref(0)
const address = ref()
const privateKey = ref()
const numText = computed(() => {
  return num.value + '个'
})
const time = ref(0)/**/
const status = ref(false)

function start() {
  /*time.value = setInterval(()=>{
    const bol = submit()
    if (bol){
      clearInterval(time.value)
    }
  },1)*/
  submit()
  return
  setInterval(()=>{
    const bol = submit()
    if (bol){
      clearInterval(time.value)
    }
  },0)
  /*setInterval(()=>{
    const bol = submit()
    if (bol){
      clearInterval(time.value)
    }
  },1)
  setInterval(()=>{
    const bol = submit()
    if (bol){
      clearInterval(time.value)
    }
  },1)
  setInterval(()=>{
    const bol = submit()
    if (bol){
      clearInterval(time.value)
    }
  },1)*/
}
function submit() {
  console.time('submit')
  num.value += 1; // 每次生成钱包时计数器加1
  const wallet = ethers.Wallet.createRandom(); // 生成随机钱包
  let addr = wallet.address; // 获取钱包地址
  console.timeEnd('submit')
  // 前缀 和 后缀 的处理
  const prefix = "";
  const suffix = "88";
  console.time('submit1')
  // 检查地址是否符合条件
  if ((!prefix || addr.slice(2).startsWith(prefix)) &&
      (!suffix || addr.endsWith(suffix))) {
    address.value = addr;
    privateKey.value = wallet.privateKey;
    status.value = true;
    return true;
  }
  console.timeEnd('submit1')
  return false;
}
</script>